package com.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

import com.dao.CommonDAO;
import com.dao.SysuserDAO;
import com.model.Familycy;
import com.model.Familyda;
import com.model.Notice;
import com.model.Sysuser;
import com.opensymphony.xwork2.ActionSupport;
import com.util.Info;
import com.util.Pagination;

public class FamilycyAction extends ActionSupport
{
	private Integer id;
	private String encid;
	private String tname;
	private String idcard;
	private String pwd;
	private String sex;
	private String tel;
	private String birth;
	private String mz;
	private String addr;
	private String jhrname;
	private String jhrtel;
	private String jhrxx;
	private String jhrunit;
	private String jhraddr;
	private String fno;
	private String delstatus;
	private String jb;
	private int index=1;
	String no;
	String suc;
	private String utype;
	private CommonDAO commonDAO;
	
	
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getEncid() {
		return encid;
	}
	public void setEncid(String encid) {
		this.encid = encid;
	}
	public String getTname() {
		return tname;
	}
	public void setTname(String tname) {
		this.tname = tname;
	}
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getBirth() {
		return birth;
	}
	public void setBirth(String birth) {
		this.birth = birth;
	}
	public String getMz() {
		return mz;
	}
	public void setMz(String mz) {
		this.mz = mz;
	}
	public String getAddr() {
		return addr;
	}
	public void setAddr(String addr) {
		this.addr = addr;
	}
	public String getJhrname() {
		return jhrname;
	}
	public void setJhrname(String jhrname) {
		this.jhrname = jhrname;
	}
	public String getJhrtel() {
		return jhrtel;
	}
	public void setJhrtel(String jhrtel) {
		this.jhrtel = jhrtel;
	}
	public String getJhrxx() {
		return jhrxx;
	}
	public void setJhrxx(String jhrxx) {
		this.jhrxx = jhrxx;
	}
	public String getJhrunit() {
		return jhrunit;
	}
	public void setJhrunit(String jhrunit) {
		this.jhrunit = jhrunit;
	}
	public String getJhraddr() {
		return jhraddr;
	}
	public void setJhraddr(String jhraddr) {
		this.jhraddr = jhraddr;
	}
	public String getFno() {
		return fno;
	}
	public void setFno(String fno) {
		this.fno = fno;
	}
	public String getDelstatus() {
		return delstatus;
	}
	public void setDelstatus(String delstatus) {
		this.delstatus = delstatus;
	}
	public String getJb() {
		return jb;
	}
	public void setJb(String jb) {
		this.jb = jb;
	}
	public int getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
	public String getNo() {
		return no;
	}
	public void setNo(String no) {
		this.no = no;
	}
	public String getSuc() {
		return suc;
	}
	public void setSuc(String suc) {
		this.suc = suc;
	}
	public String getUtype() {
		return utype;
	}
	public void setUtype(String utype) {
		this.utype = utype;
	}
	public CommonDAO getCommonDAO() {
		return commonDAO;
	}
	public void setCommonDAO(CommonDAO commonDAO) {
		this.commonDAO = commonDAO;
	}
	//添加
	public String FamilycyAdd(){
			Familycy familycy = new Familycy();
			familycy.setEncid(Info.getAutoId());
			familycy.setTname(tname);
			familycy.setPwd(pwd);
			familycy.setIdcard(idcard);
			familycy.setSex(sex);
			familycy.setTel(tel);
			familycy.setBirth(birth);
			familycy.setMz(mz);
			familycy.setAddr(addr);
			familycy.setJhrname(jhrname);
			familycy.setJhrtel(jhrtel);
			familycy.setJhrxx(jhrxx);
			familycy.setJhrunit(jhrunit);
			familycy.setJhraddr(jhraddr);
			familycy.setFno(fno);
		  	familycy.setDelstatus("0");
		  	familycy.setJb(jb==null?"":jb);
		  	ArrayList<Familycy> list = (ArrayList<Familycy>)commonDAO.findByHql(" from Familycy where idcard='"+idcard+"' and delstatus='0'");
		  	if(list.size()>0){
		  		no="";
		  	}else{
		  		commonDAO.save(familycy);
				suc="";
		  	}
			return "success";
	}
	//编辑
	public String FamilycyEdit(){
		Familycy familycy = (Familycy)commonDAO.findById(id, "Familycy");
		familycy.setTname(tname);
		familycy.setPwd(pwd);
		familycy.setSex(sex);
		familycy.setTel(tel);
		familycy.setBirth(birth);
		familycy.setMz(mz);
		familycy.setAddr(addr);
		familycy.setJhrname(jhrname);
		familycy.setJhrtel(jhrtel);
		familycy.setJhrxx(jhrxx);
		familycy.setJhrunit(jhrunit);
		familycy.setJhraddr(jhraddr);
	  	familycy.setJb(jb);
		commonDAO.update(familycy);
		id = id;
		suc="";
		return "success";
	}
	
	
	//前台登陆
	public String cylogin(){
		 	Map session= ServletActionContext.getContext().getSession();
				String hql="from Familycy where idcard='"+idcard+"' and pwd='"+pwd+"'  and delstatus='0' ";
				Object[] con={idcard,pwd,utype};
				List list=commonDAO.findByHql(hql);
				if(list.size()!=0){
					Familycy familycy=(Familycy)list.get(0);
					 session.put("cy", familycy);
					 suc="";
					 return "success";
				}else{
					no="";
					return "erro";
				}
		}
	
	//修改个人信息
	public String cygrinfo()
	{
		Familycy familycy = (Familycy)commonDAO.findById(id, "Familycy");
		familycy.setTname(tname);
		familycy.setPwd(pwd);
		familycy.setSex(sex);
		familycy.setTel(tel);
		familycy.setAddr(addr);
		commonDAO.update(familycy);
		id = id;
		suc="";
		return "success";
	}
	
	public String stuexit(){
		Map session= ServletActionContext.getContext().getSession();
		session.remove("cy");
		return "success";
	}
}
